package com.lili.controller.troop;

import com.lili.base.constants.ResponseConstant;
import com.lili.base.context.WebContext;
import com.lili.base.vo.ResultAPI;
import com.lili.pojo.User;
import com.lili.service.*;
import com.lili.vo.response.troop.*;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/troop/dashboard/")
@RestController("troopDashBoardController")
@Api(value = "士兵首页信息查询", tags = "士兵首页信息API")
public class DashBoardController {

    private final ExamService examService;

    private final ExamRecordService examRecordService;

    private final WebContext webContext;

    @Autowired
    public DashBoardController(ExamService examService, WebContext webContext, ExamRecordService examRecordService) {
        this.examService = examService;
        this.webContext = webContext;
        this.examRecordService = examRecordService;
    }


    /**
     * 得到士兵界面首页的试卷
     *
     * @return
     */
    @GetMapping("index")
    @ApiOperation("首页的试卷信息")
    public ResultAPI<List<TroopExamRespVO>> index() {
        User user = webContext.getCurrentUser();
        Integer classesId = user.getClassesId();
        Integer userId = user.getId();
        List<TroopExamRespVO> vos = examService.selectRecentExam(classesId, userId);
        return new ResultAPI<>(200, "查询成功", vos);
    }

    @GetMapping("chart")
    @ApiOperation("首页的考核成绩")
    public ResultAPI<ChartVO> chart() {
        User user = webContext.getCurrentUser();
        ChartVO chartVO = examRecordService.selectIndexChart(user);
        return new ResultAPI<>(ResponseConstant.SUCCESS, "", chartVO);
    }

}
